<template>
  <div class="container">
    <div class="top">
      请绑定您本人银行卡
    </div>
    <div class="form">
      <div class="section">
        <div class="left">持卡人姓名</div>
        <input class="inp"
               placeholder="请输入持卡人姓名"
               maxlength="10"
               v-model="user_name">
      </div>
      <div class="section">
        <div class="left">卡号</div>
        <input class="inp"
               type="number"
               placeholder="请输入银行卡号"
               maxlength="20"
               v-model="card_num">
      </div>
      <p class="tips">推荐银行：中国银行，中国工商银行，中国建设银行，中国农业银行，中国光大银行。</p>
    </div>
    <div class="sub-btn"
         @click="save()">
      确定
    </div>
  </div>
</template>


<script>
import common from "@/assets/js/mmk_common.js";
export default {
  data () {
    return {
      user_name: "",
      card_num: ""
    };
  },
  methods: {
    save () {
      if (this.user_name.trim() == "") {
        common.mmk_Loading(2, "请输入持卡人姓名")
        return false;
      } else if (this.card_num.trim() == "") {
        common.mmk_Loading(2, "请输入银行卡卡号")
        return false;
      } else {
        common.mmk_Loading(0)
        common.fly_post("api/v4_2/user_cards/create", {
          card_num: this.card_num,
          realname: this.user_name
        }, result => {
          common.mmk_Loading(1)
          let res = result.data;
          if (res.status_code == 0) {
            wx.showToast({
              title: "添加成功", //提示的内容,
              icon: "success", //图标,
              duration: 2000, //延迟时间,
              mask: true, //显示透明蒙层，防止触摸穿透,
              success: res => {
                wx.navigateBack({
                  delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
                });
              }
            });
          } else {
            common.mmk_Loading(2, res.message)
          }
        })
      }
    }
  },
  onLoad () {
    wx.setNavigationBarTitle({
      title: "添加银行卡"
    });
    Object.assign(this.$data, this.$options.data());
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: rgba(243, 244, 246, 1);
  .top {
    height: 37px;
    padding-left: 15px;
    line-height: 37px;
    font-size: 12px;
    font-family: "Medium";
    font-weight: 500;
    color: rgba(136, 136, 136, 1);
  }
  .form {
    width: 100%;
    padding-bottom: 15px;
    .section {
      height: 44px;
      line-height: 44px;
      display: flex;
      padding: 0 15px;
      background-color: #fff;
      position: relative;
      .left {
        width: 70px;
        height: 100%;
        // text-align: justify;
        // text-align-last: justify;
        font-size: 14px;
        font-weight: bold;
        font-family: "Medium";
        font-weight: 500;
        color: rgba(68, 68, 68, 1);
      }
      .inp {
        flex: 1;
        height: 100%;
        line-height: 44px;
        font-size: 14px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        padding-left: 25px;
      }
      .btn {
        height: 30px;
        padding: 0 15px;
        line-height: 30px;
        text-align: center;
        border-radius: 30px;
        border: 1px solid rgba(247, 73, 104, 1);
        font-size: 12px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(247, 73, 104, 1);
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 99;
      }
      &:nth-of-type(odd) {
        border-bottom: 1px solid rgba(238, 238, 238, 1);
      }
      &:nth-of-type(2) {
        margin-bottom: 10px;
      }
    }
    .check-box {
      margin: 0 15px;
      margin-top: 12px;
      .title {
        font-size: 14px;
        font-family: "PingFangSC-Regular";
        font-weight: 400;
        color: rgba(102, 102, 102, 1);
      }
      .check {
        height: 50px;
        display: flex;
        width: 100%;
        .inp {
          width: 180px;
          height: 100%;
          line-height: 50px;
          border-bottom: 1px solid rgba(204, 204, 204, 0.3);
        }
        .button {
          flex: 1;
          position: relative;
          .btn {
            height: 38px;
            min-width: 134px;
            line-height: 38px;
            text-align: center;
            border-radius: 8px;
            border: 1px solid rgba(204, 204, 204, 0.29751);
            font-size: 14px;
            font-family: "PingFangSC-Regular";
            font-weight: 400;
            color: rgba(102, 102, 102, 1);
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
          }
        }
      }
    }
  }
  .tips {
    width: 100%;
    box-sizing: border-box;
    padding: 0 15px;
    font-size: 12px;
    color: rgba(153, 153, 153, 1);
    line-height: 17px;
  }
  .sub-btn {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    background: #ff383e;
    font-size: 17px;
    font-family: "PingFangSC-Regular";
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    position: absolute;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
  }
}
</style>

